source('../env.R')
Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
── Attaching core tidyverse packages ─────────────────────────────────────────────────────────────────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.4.4 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ purrr 1.0.2 ── Conflicts ───────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to force all conflicts to become errorsRegistered S3 methods overwritten by 'dbplyr':
method from
print.tbl_lazy
print.tbl_sql
Attaching package: ‘dbplyr’
The following objects are masked from ‘package:dplyr’:
ident, sql
Loading required package: ape
Attaching package: ‘ape’
The following object is masked from ‘package:dplyr’:
where
Loading required package: maps
Attaching package: ‘maps’
The following object is masked from ‘package:purrr’:
map
Please cite the eBird Status and Trends data using:
Fink, D., T. Auer, A. Johnston, M. Strimas-Mackey, S. Ligocki, O. Robinson,
W. Hochachka, L. Jaromczyk, C. Crowley, K. Dunham, A. Stillman, I. Davies,
A. Rodewald, V. Ruiz-Gutierrez, C. Wood. 2023.
eBird Status and Trends, Data Version: 2022; Released: 2023. Cornell Lab of
Ornithology, Ithaca, New York. https://doi.org/10.2173/ebirdst.2022
This version of the package provides access to the 2022 version of the eBird
Status and Trends Data Products. Access to the 2022 data will be provided
until November 2024 when it will be replaced by the 2023 data. At that
point, you will be required to update this R package and transition to using
the new data.
terra 1.7.71
Attaching package: ‘terra’
The following object is masked from ‘package:phytools’:
rescale
The following objects are masked from ‘package:ape’:
rotate, trans, zoom
The following object is masked from ‘package:tidyr’:
extract
Loading required package: permute
Loading required package: lattice
This is vegan 2.6-4
Attaching package: ‘vegan’
The following object is masked from ‘package:phytools’:
scores
Loading required package: mvtnorm
Loading required package: survival
Loading required package: TH.data
Loading required package: MASS
Attaching package: ‘MASS’
The following object is masked from ‘package:terra’:
area
The following object is masked from ‘package:dplyr’:
select
Attaching package: ‘TH.data’
The following object is masked from ‘package:MASS’:
geyser
Attaching package: ‘ggpubr’
The following object is masked from ‘package:terra’:
rotate
The following object is masked from ‘package:ape’:
rotate
Loading required package: nlme
Attaching package: ‘nlme’
The following object is masked from ‘package:dplyr’:
collapse
Registered S3 method overwritten by 'GGally':
method from
+.gg ggplot2
Attaching package: ‘GGally’
The following object is masked from ‘package:terra’:
wrap
ggtree v3.11.0 For help: https://yulab-smu.top/treedata-book/
If you use the ggtree package suite in published research, please cite the appropriate paper(s):
Guangchuang Yu, David Smith, Huachen Zhu, Yi Guan, Tommy Tsan-Yuk Lam. ggtree: an R package for visualization and annotation
of phylogenetic trees with their covariates and other associated data. Methods in Ecology and Evolution. 2017, 8(1):28-36.
doi:10.1111/2041-210X.12628
Shuangbin Xu, Lin Li, Xiao Luo, Meijun Chen, Wenli Tang, Li Zhan, Zehan Dai, Tommy T. Lam, Yi Guan, Guangchuang Yu. Ggtree:
A serialized data object for visualization of a phylogenetic tree and annotation data. iMeta 2022, 1(4):e56.
doi:10.1002/imt2.56
G Yu. Data Integration, Manipulation and Visualization of Phylogenetic Trees (1st ed.). Chapman and Hall/CRC. 2022. ISBN:
9781032233574
Attaching package: ‘ggtree’
The following object is masked from ‘package:nlme’:
collapse
The following object is masked from ‘package:ggpubr’:
rotate
The following objects are masked from ‘package:terra’:
flip, inset, rotate
The following object is masked from ‘package:ape’:
rotate
The following object is masked from ‘package:tidyr’:
expand
Attaching package: ‘foreach’
The following objects are masked from ‘package:purrr’:
accumulate, when
Attaching package: ‘scales’
The following object is masked from ‘package:terra’:
rescale
The following object is masked from ‘package:phytools’:
rescale
The following object is masked from ‘package:purrr’:
discard
The following object is masked from ‘package:readr’:
col_factor
Spherical geometry (s2) switched off
Here we create traits based on the “AVONET: Morphological, Ecological and Geographical Data for All Birds.” (2022) morphology and trait database.
birdlife_jetz_mapping = read_csv(MY_BIRDLIFE_COL_MAPPING)
Rows: 353 Columns: 35── Column specification ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (24): SpeciesName_v8, CommonName_v8, RedList2023, Synonyms_v8, SpeciesName_v7, CommonName_v7, RedList2022, Synonyms_v7, SpeciesName...
dbl (11): SISRecID_v8, SpcRecID_v8, SISRecID_v7, SpcRecID_v7, SISRecID_v6, SpcRecID_v6, SISRecID_v5, SpcRecID_v5, SISRecID_v4, SpcRecID...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
birdlife_jetz_mapping
avonet_birdlife = read_csv(DL_AVONET)
Rows: 11009 Columns: 37── Column specification ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (13): Species1, Family1, Order1, Avibase.ID1, Mass.Source, Mass.Refs.Other, Inference, Traits.inferred, Reference.species, Habitat,...
dbl (24): Sequence, Total.individuals, Female, Male, Unknown, Complete.measures, Beak.Length_Culmen, Beak.Length_Nares, Beak.Width, Bea...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
avonet_birdlife
avonet_columbidae = avonet_birdlife[avonet_birdlife$Order1 == 'Columbiformes',]
avonet_columbidae
Avonet uses Birdlife V5 taxonomy.
birdlife_jetz_mapping[!(birdlife_jetz_mapping$SpeciesName_v5 %in% avonet_columbidae$Species1),]
We can check that we are only losing species that are absent from Birdlife V8 by checking our Birdlife to Jetz mapping scripts.
avonet_columbidae[!(avonet_columbidae$Species1 %in% birdlife_jetz_mapping$SpeciesName_v5),]
avonet_jetz = avonet_columbidae %>%
inner_join(birdlife_jetz_mapping[,c('SpeciesName_v5', 'JetzSpeciesName')], by=c('Species1' = 'SpeciesName_v5')) %>%
group_by(JetzSpeciesName) %>%
summarise(
beak_length_culmen = mean(Beak.Length_Culmen),
beak_length_nares = mean(Beak.Length_Nares),
beak_width = mean(Beak.Width),
beak_depth = mean(Beak.Depth),
tarsus_length = mean(Tarsus.Length),
wing_length = mean(Wing.Length),
kipps_distance = mean(Kipps.Distance),
secondary1 = mean(Secondary1),
handwing_index = mean(`Hand-Wing.Index`),
tail_length = mean(Tail.Length),
mass = mean(Mass),
habitat = toString(unique(na.omit(Habitat))),
habitat_density = toString(unique(na.omit(Habitat.Density))),
migration = toString(unique(na.omit(Migration))),
trophic_level = toString(unique(na.omit(Trophic.Level))),
trophic_niche = toString(unique(na.omit(Trophic.Niche))),
primary_lifestyle = toString(unique(na.omit(Primary.Lifestyle)))
)
avonet_jetz
Check we have just one row per species
length(unique(avonet_jetz$JetzSpeciesName)) == nrow(avonet_jetz)
[1] TRUE
avonet_jetz[
grepl(',', avonet_jetz$habitat, fixed = TRUE) |
grepl(',', avonet_jetz$habitat_density, fixed = TRUE) |
grepl(',', avonet_jetz$migration, fixed = TRUE) |
grepl(',', avonet_jetz$trophic_level, fixed = TRUE) |
grepl(',', avonet_jetz$trophic_niche, fixed = TRUE) |
grepl(',', avonet_jetz$primary_lifestyle, fixed = TRUE),
c('JetzSpeciesName', 'habitat', 'habitat_density', 'migration', 'trophic_level', 'trophic_niche', 'primary_lifestyle')
]
Species that are migratory and year round residents
avonet_jetz[avonet_jetz$JetzSpeciesName %in% c('Columba_palumbus', 'Patagioenas_fasciata'),]
avonet_jetz$migration[avonet_jetz$JetzSpeciesName %in% c('Macropygia_amboinensis', 'Treron_calvus')] = '1'
Tropic niche of Macropygia amboinensis from avibase is Omnivore https://avibase.bsc-eoc.org/species.jsp?lang=EN&avibaseid=FD5160925CD583C1&sec=lifehistory
avonet_jetz$trophic_niche[avonet_jetz$JetzSpeciesName %in% c('Macropygia_amboinensis')] = 'Omnivore'
avonet_jetz[
grepl(',', avonet_jetz$habitat, fixed = TRUE) |
grepl(',', avonet_jetz$habitat_density, fixed = TRUE) |
grepl(',', avonet_jetz$migration, fixed = TRUE) |
grepl(',', avonet_jetz$trophic_level, fixed = TRUE) |
grepl(',', avonet_jetz$trophic_niche, fixed = TRUE) |
grepl(',', avonet_jetz$primary_lifestyle, fixed = TRUE),
c('JetzSpeciesName', 'habitat', 'habitat_density', 'migration', 'trophic_level', 'trophic_niche', 'primary_lifestyle')
]
avonet_jetz$habitat = as.factor(avonet_jetz$habitat)
avonet_jetz$habitat_density = as.factor(avonet_jetz$habitat_density)
avonet_jetz$migration = as.factor(avonet_jetz$migration)
avonet_jetz$trophic_level = as.factor(avonet_jetz$trophic_level)
avonet_jetz$trophic_niche = as.factor(avonet_jetz$trophic_niche)
avonet_jetz$primary_lifestyle = as.factor(avonet_jetz$primary_lifestyle)
This uses a methodogy from Trisos (2014) and Tom P. Bregman and Tobias (2016) to create traits that describe a species lifestyle.
These traits are namely: * Overall body size. * trophic - beak shape (beak length, width, depth) - measures competitive exclusion (e.g. over-dispersion) via accentuation of foraging differences * locomotory (wing, tail, tarsus length) * tarsus-to-tail length ratio
set.seed(778899)
trophic_trait_pca = rda(avonet_jetz[,c('beak_length_culmen', 'beak_width', 'beak_depth')])
avonet_jetz$trophic_pc1 = trophic_trait_pca$Ybar[,1]
avonet_jetz$trophic_pc2 = trophic_trait_pca$Ybar[,2]
avonet_jetz$trophic_pc3 = trophic_trait_pca$Ybar[,3]
How does PC1 explain trophic niche?
trophic_pc1_aov = aov(trophic_pc1 ~ trophic_niche,
data = avonet_jetz
)
summary(trophic_pc1_aov)
Df Sum Sq Mean Sq F value Pr(>F)
trophic_niche 2 3.676 1.8382 20.87 0.00000000326 ***
Residuals 301 26.514 0.0881
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
summary(glht(trophic_pc1_aov,
linfct = mcp(trophic_niche = "Tukey")
))
Simultaneous Tests for General Linear Hypotheses
Multiple Comparisons of Means: Tukey Contrasts
Fit: aov(formula = trophic_pc1 ~ trophic_niche, data = avonet_jetz)
Linear Hypotheses:
Estimate Std. Error t value Pr(>|t|)
Granivore - Frugivore == 0 -0.247299 0.040557 -6.098 < 0.000001 ***
Omnivore - Frugivore == 0 0.008417 0.044323 0.190 0.98
Omnivore - Granivore == 0 0.255716 0.050218 5.092 0.00000197 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Adjusted p values reported -- single-step method)
How does PC2 explain trophic niche?
trophic_pc2_aov = aov(trophic_pc2 ~ trophic_niche,
data = avonet_jetz
)
summary(trophic_pc2_aov)
Df Sum Sq Mean Sq F value Pr(>F)
trophic_niche 2 0.7255 0.3627 63.96 <0.0000000000000002 ***
Residuals 301 1.7070 0.0057
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
summary(glht(trophic_pc2_aov,
linfct = mcp(trophic_niche = "Tukey")
))
Simultaneous Tests for General Linear Hypotheses
Multiple Comparisons of Means: Tukey Contrasts
Fit: aov(formula = trophic_pc2 ~ trophic_niche, data = avonet_jetz)
Linear Hypotheses:
Estimate Std. Error t value Pr(>|t|)
Granivore - Frugivore == 0 -0.11184 0.01029 -10.868 < 0.0001 ***
Omnivore - Frugivore == 0 -0.07054 0.01125 -6.272 < 0.0001 ***
Omnivore - Granivore == 0 0.04131 0.01274 3.242 0.00361 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Adjusted p values reported -- single-step method)
How does PC3 explain trophic niche?
trophic_pc3_aov = aov(trophic_pc3 ~ trophic_niche,
data = avonet_jetz
)
summary(trophic_pc3_aov)
Df Sum Sq Mean Sq F value Pr(>F)
trophic_niche 2 0.5426 0.2713 40.48 0.000000000000000269 ***
Residuals 301 2.0171 0.0067
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
summary(glht(trophic_pc3_aov,
linfct = mcp(trophic_niche = "Tukey")
))
Simultaneous Tests for General Linear Hypotheses
Multiple Comparisons of Means: Tukey Contrasts
Fit: aov(formula = trophic_pc3 ~ trophic_niche, data = avonet_jetz)
Linear Hypotheses:
Estimate Std. Error t value Pr(>|t|)
Granivore - Frugivore == 0 -0.10063 0.01119 -8.995 < 0.0001 ***
Omnivore - Frugivore == 0 -0.03585 0.01223 -2.933 0.00977 **
Omnivore - Granivore == 0 0.06477 0.01385 4.676 < 0.0001 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Adjusted p values reported -- single-step method)
avonet_jetz %>%
pivot_longer(cols = c('trophic_pc1', 'trophic_pc2', 'trophic_pc3'), names_to = 'axis') %>%
ggplot(aes(x = trophic_niche, y = value, color = axis)) +
geom_boxplot() + xlab('Trophic Niche') + ylab('PC Value')
avonet_jetz %>%
ggplot(aes(x = trophic_niche, y = trophic_pc1, fill = trophic_niche)) +
geom_violin(alpha = 0.5) +
geom_point(position = position_jitter(seed = 1, width = 0.2)) +
theme(legend.position = "none") +
labs(title = "Trophic PC1")
avonet_jetz %>%
ggplot(aes(x = trophic_niche, y = trophic_pc2, fill = trophic_niche)) +
geom_violin(alpha = 0.5) +
geom_point(position = position_jitter(seed = 1, width = 0.2)) +
theme(legend.position = "none") +
labs(title = "Trophic PC2")
ggarrange(ncol = 2, nrow = 2, common.legend = T,
ggplot(avonet_jetz, aes(y = trophic_pc1, x = trophic_pc2, color = trophic_niche)) + geom_point(),
ggplot(avonet_jetz, aes(y = trophic_pc1, x = trophic_pc3, color = trophic_niche)) + geom_point(),
ggplot(avonet_jetz, aes(y = trophic_pc3, x = trophic_pc2, color = trophic_niche)) + geom_point()
)
Is PC1 correlated to mass?
cor(avonet_jetz$trophic_pc1, avonet_jetz$mass)
[1] 0.7997893
Is PC2 correlated to mass?
cor(avonet_jetz$trophic_pc2, avonet_jetz$mass)
[1] 0.6423876
Is PC3 correlated to mass?
cor(avonet_jetz$trophic_pc3, avonet_jetz$mass)
[1] 0.5944833
set.seed(778899)
loco_trait_pca = rda(avonet_jetz[,c('tarsus_length', 'wing_length', 'tail_length')])
summary(loco_trait_pca)
Call:
rda(X = avonet_jetz[, c("tarsus_length", "wing_length", "tail_length")])
Partitioning of variance:
Inertia Proportion
Total 4004 1
Unconstrained 4004 1
Eigenvalues, and their contribution to the variance
Importance of components:
PC1 PC2 PC3
Eigenvalue 3599.459 350.94577 53.31631
Proportion Explained 0.899 0.08765 0.01332
Cumulative Proportion 0.899 0.98668 1.00000
Scaling 2 for species and site scores
* Species are scaled proportional to eigenvalues
* Sites are unscaled: weighted dispersion equal on all dimensions
* General scaling constant of scores: 33.18766
Species scores
PC1 PC2 PC3
tarsus_length 3.026 0.8724 3.7968
wing_length 25.061 5.8029 -0.4984
tail_length 18.788 -7.8810 0.0533
Site scores (weighted sums of species scores)
PC1 PC2 PC3
sit1 -0.51315 2.55439912 -1.473133
sit2 -0.77734 1.97068701 -0.285657
sit3 -0.45789 1.23403715 -0.423677
sit4 -0.99167 -0.01969641 0.474162
sit5 2.10770 6.62482101 1.139124
sit6 -1.01073 0.87860796 0.243452
sit7 -1.33630 0.23657428 0.373900
sit8 -1.84945 -0.65747797 0.277173
sit9 -1.88647 -0.68187484 0.338621
sit10 -2.15755 -0.67734893 -1.000295
sit11 0.37445 0.80128589 -1.329999
sit12 1.22660 3.59349812 -1.412819
sit13 2.37934 1.01099884 -1.606495
sit14 1.83448 1.78047900 -1.586082
sit15 1.88153 -0.29524719 -0.514557
sit16 0.10264 0.27820916 -1.625294
sit17 1.75537 -0.91833428 -1.271681
sit18 0.59958 3.36723304 -1.466872
sit19 1.64567 3.09396968 -1.605706
sit20 1.93744 1.40119053 -2.028735
sit21 -0.70539 0.73906399 -1.376901
sit22 3.11613 -1.54048403 -0.685654
sit23 2.09449 -0.31769092 -0.099696
sit24 1.94751 1.98397358 -1.959963
sit25 1.67820 3.52720836 -1.546812
sit26 1.18508 3.55432927 -1.950158
sit27 -0.06267 0.92322458 -1.826103
sit28 1.32702 2.13025288 -1.762425
sit29 0.61603 2.84816963 -1.466079
sit30 1.87654 2.73042507 -1.653498
sit31 2.52253 1.60674405 -1.515105
sit32 2.78368 1.31654397 -1.393184
sit33 2.27242 -0.30102206 -2.194325
sit34 1.01364 1.66278492 -1.694973
sit35 1.87513 0.64421323 -1.936839
sit36 1.41142 3.14347149 -1.772778
sit37 1.36485 2.26775478 -2.271911
sit38 2.41145 0.61546720 -1.988945
sit39 0.93290 -0.02443220 -1.321982
sit40 2.70292 -0.16216134 -0.198937
sit41 1.30103 1.63813645 -1.575965
sit42 1.72776 0.72977557 -1.127928
sit43 -3.00722 -1.41561609 -0.153493
sit44 -3.04393 -0.94463692 -0.127102
sit45 -3.48638 -2.30211568 0.142357
sit46 -2.38409 -2.81305196 -0.539749
sit47 -3.49043 -0.84159324 -0.110975
sit48 -3.21300 -1.09545572 -0.352763
sit49 -2.81968 -1.76070075 -0.961126
sit50 -2.28195 -2.82333945 -0.539774
sit51 -2.96009 -1.27817576 -0.196296
sit52 3.15438 -2.75027904 0.193928
sit53 0.30875 2.25502408 2.259988
sit54 -1.12545 1.39948588 0.439076
sit55 2.28999 2.25953790 -1.260281
sit56 2.32253 1.19618070 -1.103348
sit57 2.55669 -0.55310346 -1.770365
sit58 1.51521 -0.11297160 -0.159131
sit59 1.29361 1.35542473 -0.425252
sit60 1.79388 2.11695083 -1.314984
sit61 1.24413 2.80111494 -0.928681
sit62 1.19894 1.72384069 -1.698657
sit63 1.75166 -0.06836513 0.010896
sit64 1.91299 -0.32421419 -0.875359
sit65 3.92357 1.57311346 -1.280767
sit66 1.01296 1.21059903 -0.774069
sit67 3.16828 -1.31438773 -0.647479
sit68 4.90780 0.55745069 0.670252
sit69 4.82333 0.62542854 -0.779292
sit70 1.71255 -0.63765328 -0.959651
sit71 2.48776 -0.03109035 -0.663343
sit72 2.77132 0.69155469 -1.266068
sit73 2.79482 0.73843013 -0.742476
sit74 2.58497 -0.61335800 -0.949426
sit75 2.15871 1.73197985 -1.095895
sit76 2.42934 2.83430693 -1.038096
sit77 1.83151 0.06845541 -0.400232
sit78 2.88177 0.67190471 0.046313
sit79 2.99619 1.58057759 -0.675060
sit80 2.39995 0.53175486 -0.933379
sit81 2.90208 3.07284069 -1.074608
sit82 2.47048 1.56199036 -1.041936
sit83 1.84395 -0.48708749 -0.624893
sit84 1.39207 0.05462843 -1.390043
sit85 2.12834 1.24657407 -0.249044
sit86 2.13253 2.89135336 -0.551274
sit87 0.68313 1.92686129 0.009014
sit88 2.43192 1.96449769 -1.103681
sit89 1.82208 3.55821148 -0.773121
sit90 3.24186 0.20698967 -0.502579
sit91 1.63006 1.79568200 -0.452161
sit92 -2.67292 0.65752929 1.869202
sit93 -2.30581 0.65616930 2.656772
sit94 -0.69952 0.14730133 2.863059
sit95 -1.40845 1.45826721 1.941658
sit96 -0.66853 -0.44139989 0.576893
sit97 -1.09199 0.61780386 0.644687
sit98 -1.35127 1.06800317 2.881237
sit99 -1.12070 1.16751829 1.989836
sit100 -1.21340 1.01088978 2.126043
sit101 -0.48835 0.60813225 2.193811
sit102 -0.60672 0.21371033 2.484124
sit103 -2.06675 0.86542812 1.865075
sit104 -1.64791 0.67365751 2.233772
sit105 -1.96146 1.20741117 0.306687
sit106 -0.93811 0.61101695 1.682458
sit107 -0.24321 -0.12500499 4.379248
sit108 -1.17553 0.19654607 1.571841
sit109 -2.25081 -3.98184016 -0.825165
sit110 -0.34626 -3.69995803 -0.090119
sit111 -1.91883 -3.41312757 0.017455
sit112 -2.20152 -2.50670904 -0.834650
sit113 -2.15066 -3.05685183 -0.669769
sit114 -2.40058 -0.23368758 0.171302
sit115 -0.80162 -1.19769583 1.330814
sit116 -1.45955 0.33250178 1.714289
sit117 -1.22279 1.07115573 4.964143
sit118 -0.93513 1.10565606 2.475082
sit119 -0.86400 0.36279150 4.524899
sit120 -1.04236 1.42185742 4.476388
sit121 -0.75041 0.67474331 1.228509
sit122 -1.33012 1.11676612 4.512449
sit123 -0.47244 0.25420581 4.290448
sit124 -1.13285 0.67449562 4.667549
sit125 -1.44450 1.29942192 4.298270
sit126 -0.74085 0.48896043 4.160721
sit127 -1.47092 0.94681132 0.871091
sit128 -0.57775 1.57314879 1.911650
sit129 -1.70870 1.94936488 3.095291
sit130 -1.67710 1.29576335 3.193941
sit131 -0.73008 1.21404977 2.510629
sit132 -1.10049 0.50806016 0.544983
sit133 7.78429 -0.21433140 13.330489
sit134 7.88825 -0.66221689 10.835294
sit135 7.58997 -0.46731718 10.646338
sit136 1.49845 -1.11451452 -1.627604
sit137 1.86676 -1.12979378 -1.443555
sit138 2.09873 -1.11395084 -1.131658
sit139 4.03322 -0.92014170 -0.518752
sit140 1.16449 -0.77796643 0.747252
sit141 1.34911 0.22076134 0.792045
sit142 -1.22050 -0.31530738 1.777963
sit143 -1.38211 -0.07850461 1.826019
sit144 -1.19409 -0.22441854 2.157439
sit145 -0.83318 0.01961168 1.076270
sit146 -0.42352 -1.15770231 1.547037
sit147 -1.18367 -0.88431440 2.221734
sit148 -1.15126 -0.40373176 1.822113
sit149 -0.92898 -0.53338111 1.859106
sit150 -1.15348 -0.57903307 1.074029
sit151 -0.97389 -1.14001219 1.165142
sit152 -1.13785 -0.11511257 2.245523
sit153 1.17979 0.08393142 2.723058
sit154 4.33393 -0.09605192 -2.488511
sit155 1.61795 -6.10271222 -0.826958
sit156 0.87345 -3.40012745 -1.078424
sit157 0.34019 -4.92239780 -0.672395
sit158 1.73782 -5.62637776 -0.790506
sit159 -0.08434 -3.48850650 -1.111240
sit160 0.02796 -4.92106992 -1.108629
sit161 1.91897 -4.48735836 -1.293155
sit162 1.62183 -5.76774838 -1.446934
sit163 1.19266 -4.15126550 -1.397287
sit164 -2.28805 0.85435878 -0.563434
sit165 -2.74130 -0.80712158 -0.162847
sit166 -1.50974 -0.04518705 -0.792698
sit167 -2.53585 -1.53365663 0.103718
sit168 1.94998 -1.43047950 0.745227
sit169 -0.20642 0.41142332 -0.566780
sit170 0.23987 -2.35191537 0.133849
sit171 -1.43074 -5.25134275 -1.055378
sit172 1.64978 -4.20644238 8.957333
sit173 1.48967 0.75069592 -0.416232
sit174 1.72742 -0.41212457 -0.996983
sit175 0.31756 0.57643854 -1.391026
sit176 0.62793 1.28048173 -1.062690
sit177 1.52093 -0.20917555 -1.392629
sit178 0.52353 0.79899816 -1.685328
sit179 -0.74115 -0.28424801 -1.244974
sit180 1.26768 1.43421352 -1.212822
sit181 0.76036 0.51901197 -0.861592
sit182 1.39662 2.78899886 -1.126447
sit183 -0.27117 -0.04087103 -1.464754
sit184 0.70181 0.92046443 -1.539271
sit185 1.66026 1.35762955 -0.823326
sit186 0.80171 -1.93566404 -1.278713
sit187 0.15662 2.01909536 -1.515210
sit188 1.60876 0.15098568 -1.611221
sit189 -0.26555 -1.02835411 -1.242355
sit190 -1.00115 -1.81049543 -0.186670
sit191 -0.59663 -2.09086044 -0.365634
sit192 -0.71074 -1.49429291 -0.762925
sit193 -1.07747 -0.65132273 -0.760903
sit194 -1.28331 -0.28706863 -0.048439
sit195 -1.70323 -0.27249173 -0.595042
sit196 1.03085 0.59590396 -0.410057
sit197 -0.37790 0.66918129 0.432488
sit198 0.15229 4.10506356 -1.121890
sit199 -2.84409 0.49562513 -0.195880
sit200 -1.99175 1.66685655 0.119917
sit201 -0.11558 -4.19294320 -0.450413
sit202 -1.31657 0.02040541 0.855583
sit203 0.31619 -0.74145966 -0.652559
sit204 -1.63922 -0.11238852 1.143241
sit205 -2.22362 0.73008407 -0.375533
sit206 0.37947 0.06338301 0.363126
sit207 -1.27511 1.34350627 -0.113567
sit208 -2.18564 0.31796124 0.347331
sit209 0.47149 -1.87341964 0.497752
sit210 -2.02943 0.63934119 0.307014
sit211 -2.21902 0.36289964 -0.005121
sit212 0.02184 -1.19471987 0.436800
sit213 -2.01694 1.37684650 -0.109422
sit214 -1.93269 1.42828942 0.312024
sit215 -0.85358 -0.45745834 1.518196
sit216 -2.42525 1.77490543 0.045519
sit217 -1.22014 -0.00623636 -1.427514
sit218 -2.55125 1.83219151 0.396152
sit219 -1.02230 -0.28887175 -0.387737
sit220 -2.27094 0.97581833 0.106136
sit221 0.36377 -2.44147759 -0.497410
sit222 0.73655 -1.65415040 -0.474994
sit223 -1.97741 -0.11448090 -0.035324
sit224 0.03243 -0.76096313 0.802778
sit225 -2.89286 0.00009782 0.009514
sit226 -3.38601 0.64900998 -0.378650
sit227 -0.44666 0.02054746 0.056893
sit228 -1.24302 1.98821250 -0.524307
sit229 -1.89221 1.22035457 0.327541
sit230 -0.80572 1.52658387 0.339419
sit231 -1.72323 0.60635696 0.070563
sit232 -1.80777 1.01419310 0.116662
sit233 -0.94583 0.04652115 -0.262361
sit234 -2.60327 0.38146929 -0.651302
sit235 -1.32968 1.07703099 0.359882
sit236 -1.70870 -0.08913622 0.929897
sit237 -1.90955 1.04608937 -0.566758
sit238 -1.81381 0.71728132 -0.383155
sit239 -1.81198 0.51996729 -0.181245
sit240 -1.90789 0.39961480 0.818320
sit241 -2.46323 1.02915203 -0.213778
sit242 0.12569 -1.38917274 0.117773
sit243 -1.66488 0.99619132 -0.381567
sit244 -1.17338 1.66358772 0.100546
sit245 -2.30985 1.11163620 0.132278
sit246 -2.47643 1.04346284 -0.009008
sit247 -1.26831 1.96581558 -0.551684
sit248 3.14518 -3.26405079 -1.234615
sit249 2.19063 -3.48551554 -1.450136
sit250 5.24569 -10.78583410 -2.049622
sit251 -0.98263 -0.37869901 2.366742
sit252 -0.48791 -3.17780974 -0.531762
sit253 -0.99325 -2.01243851 -0.936698
sit254 -0.16778 -0.76944017 -0.234072
sit255 -0.52887 -0.73870287 -0.677634
sit256 0.53749 -1.28384897 -1.257399
sit257 0.28737 -1.47145584 -0.870096
sit258 0.14787 0.03070789 -1.630811
sit259 0.16874 -0.10976982 -1.615166
sit260 0.50292 -0.81663207 -0.665590
sit261 -0.83681 -1.29583213 -0.778287
sit262 -0.35030 -0.16473613 -1.267878
sit263 0.27795 -0.46764660 -1.093222
sit264 -1.43005 0.26629625 -1.586214
sit265 0.01431 0.23438047 -1.360462
sit266 -1.10117 -0.80949604 -0.784684
sit267 1.02695 -5.28889805 -0.503417
sit268 -0.73171 0.96920300 -1.224442
sit269 -0.36209 1.35849595 -0.778829
sit270 0.65263 1.40963850 -1.928518
sit271 -1.55303 1.04341080 -0.929296
sit272 -0.98440 0.69008148 -0.326811
sit273 1.02566 0.21278024 -0.818303
sit274 -1.26889 1.07065501 -1.372712
sit275 -1.05745 0.59209646 -0.325097
sit276 -2.17462 0.76580188 -1.107567
sit277 -0.14598 -1.39838448 -0.541514
sit278 -0.54267 2.42770948 -0.419667
sit279 0.40127 1.58906815 -1.242661
sit280 -0.88415 1.58940503 -0.565059
sit281 -0.31812 0.90753291 -0.407378
sit282 -0.26631 1.50109745 -0.321668
sit283 0.18600 -3.42732087 -1.051037
sit284 0.47603 0.28113418 -1.475808
sit285 0.15282 -0.36152398 -1.333934
sit286 -0.71448 1.13231994 -0.064118
sit287 -1.40099 0.65827245 -0.777622
sit288 0.17512 1.06378668 -1.073425
sit289 0.37886 -0.31289214 4.980146
sit290 1.77048 -4.04175395 -1.264028
sit291 1.68047 -2.45447428 -1.254102
sit292 -2.25708 -1.12623239 -0.396436
sit293 -2.21250 -1.34958981 -0.354305
sit294 -1.14117 -2.18535301 1.248927
sit295 -2.18688 -0.55305547 -0.426048
sit296 -1.94774 -1.12088979 0.172265
sit297 -3.37536 -3.17955252 0.123786
sit298 -0.10528 -0.86867212 -0.353268
sit299 -1.18158 -0.47960233 -0.585695
sit300 -0.78541 0.02120601 -0.516088
sit301 -1.98037 1.17408954 0.171393
sit302 -0.10398 -3.11320182 1.267585
sit303 -0.42240 -2.39117001 -1.120275
sit304 -0.46773 0.22195373 -0.262311
avonet_jetz$locomotory_pc1 = loco_trait_pca$Ybar[,1]
avonet_jetz$locomotory_pc2 = loco_trait_pca$Ybar[,2]
avonet_jetz$locomotory_pc3 = loco_trait_pca$Ybar[,3]
How does PC1 explain lifstyle?
loco_lifstyle_pc1_aov = aov(locomotory_pc1 ~ primary_lifestyle,
data = avonet_jetz
)
summary(loco_lifstyle_pc1_aov)
Df Sum Sq Mean Sq F value Pr(>F)
primary_lifestyle 2 1.77 0.8871 3.08 0.0474 *
Residuals 301 86.68 0.2880
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
summary(glht(loco_lifstyle_pc1_aov,
linfct = mcp(primary_lifestyle = "Tukey")
))
Simultaneous Tests for General Linear Hypotheses
Multiple Comparisons of Means: Tukey Contrasts
Fit: aov(formula = locomotory_pc1 ~ primary_lifestyle, data = avonet_jetz)
Linear Hypotheses:
Estimate Std. Error t value Pr(>|t|)
Insessorial - Generalist == 0 -0.004717 0.154295 -0.031 0.9995
Terrestrial - Generalist == 0 0.152607 0.156886 0.973 0.5782
Terrestrial - Insessorial == 0 0.157324 0.064159 2.452 0.0351 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Adjusted p values reported -- single-step method)
How does PC2 explain lifstyle?
loco_lifstyle_pc2_aov = aov(locomotory_pc2 ~ primary_lifestyle,
data = avonet_jetz
)
summary(loco_lifstyle_pc2_aov)
Df Sum Sq Mean Sq F value Pr(>F)
primary_lifestyle 2 195.8 97.89 13.33 0.00000284 ***
Residuals 301 2210.6 7.34
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
summary(glht(loco_lifstyle_pc2_aov,
linfct = mcp(primary_lifestyle = "Tukey")
))
Simultaneous Tests for General Linear Hypotheses
Multiple Comparisons of Means: Tukey Contrasts
Fit: aov(formula = locomotory_pc2 ~ primary_lifestyle, data = avonet_jetz)
Linear Hypotheses:
Estimate Std. Error t value Pr(>|t|)
Insessorial - Generalist == 0 1.2096 0.7792 1.552 0.252
Terrestrial - Generalist == 0 -0.4475 0.7923 -0.565 0.830
Terrestrial - Insessorial == 0 -1.6571 0.3240 -5.115 <0.0001 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Adjusted p values reported -- single-step method)
How does PC3 explain lifstyle?
loco_lifstyle_pc3_aov = aov(locomotory_pc3 ~ primary_lifestyle,
data = avonet_jetz
)
summary(loco_lifstyle_pc3_aov)
Df Sum Sq Mean Sq F value Pr(>F)
primary_lifestyle 2 71.1 35.57 7.447 0.000697 ***
Residuals 301 1437.7 4.78
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
summary(glht(loco_lifstyle_pc3_aov,
linfct = mcp(primary_lifestyle = "Tukey")
))
Simultaneous Tests for General Linear Hypotheses
Multiple Comparisons of Means: Tukey Contrasts
Fit: aov(formula = locomotory_pc3 ~ primary_lifestyle, data = avonet_jetz)
Linear Hypotheses:
Estimate Std. Error t value Pr(>|t|)
Insessorial - Generalist == 0 0.3500 0.6284 0.557 0.834768
Terrestrial - Generalist == 0 -0.6582 0.6389 -1.030 0.541379
Terrestrial - Insessorial == 0 -1.0082 0.2613 -3.858 0.000362 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Adjusted p values reported -- single-step method)
avonet_jetz %>%
pivot_longer(cols = c('locomotory_pc1', 'locomotory_pc2', 'locomotory_pc3'), names_to = 'axis') %>%
ggplot(aes(x = primary_lifestyle, y = value, color = axis)) +
geom_boxplot() + xlab('Primary Lifestype') + ylab('PC Value')
avonet_jetz %>%
ggplot(aes(x = primary_lifestyle, y = locomotory_pc1, fill = primary_lifestyle)) +
geom_violin(alpha = 0.5) +
geom_point(position = position_jitter(seed = 1, width = 0.2)) +
theme(legend.position = "none") +
labs(title = "Locomotory PC1")
avonet_jetz %>%
ggplot(aes(x = primary_lifestyle, y = locomotory_pc2, fill = primary_lifestyle)) +
geom_violin(alpha = 0.5) +
geom_point(position = position_jitter(seed = 1, width = 0.2)) +
theme(legend.position = "none") +
labs(title = "Locomotory PC2")
avonet_jetz %>%
pivot_longer(cols = c('locomotory_pc1', 'locomotory_pc2', 'locomotory_pc3'), names_to = 'axis') %>%
ggplot(aes(x = migration, y = value, color = axis)) +
geom_boxplot() + xlab('Migration') + ylab('PC Value')
avonet_jetz %>%
ggplot(aes(x = migration, y = locomotory_pc1, fill = migration)) +
geom_violin(alpha = 0.5) +
geom_point(position = position_jitter(seed = 1, width = 0.2)) +
theme(legend.position = "none") +
labs(title = "Locomotory PC1")
avonet_jetz %>%
ggplot(aes(x = migration, y = locomotory_pc2, fill = migration)) +
geom_violin(alpha = 0.5) +
geom_point(position = position_jitter(seed = 1, width = 0.2)) +
theme(legend.position = "none") +
labs(title = "Locomotory PC2")
ggarrange(ncol = 2, nrow = 2, common.legend = T,
ggplot(avonet_jetz, aes(y = locomotory_pc1, x = locomotory_pc2, color = primary_lifestyle)) + geom_point(),
ggplot(avonet_jetz, aes(y = locomotory_pc1, x = locomotory_pc3, color = primary_lifestyle)) + geom_point(),
ggplot(avonet_jetz, aes(y = locomotory_pc3, x = locomotory_pc2, color = primary_lifestyle)) + geom_point()
)
Is PC1 correlated to mass?
cor(avonet_jetz$locomotory_pc1, avonet_jetz$mass)
[1] 0.8332333
Is PC2 correlated to mass?
cor(avonet_jetz$locomotory_pc2, avonet_jetz$mass)
[1] 0.7988238
Is PC3 correlated to mass?
cor(avonet_jetz$locomotory_pc3, avonet_jetz$mass)
[1] 0.6700626
Here we select the second axis of each trait PCA.
trait_database = avonet_jetz %>%
dplyr::select(JetzSpeciesName, beak_width, trophic_pc2, locomotory_pc2, mass, handwing_index) %>%
rename(jetz_species_name=JetzSpeciesName, gape_width=beak_width, trophic_trait=trophic_pc2, locomotory_trait=locomotory_pc2)
trait_database
write_csv(trait_database, filename(TAXONOMY_OUTPUT_DIR, 'traits_jetz.csv'))
ggplot(trait_database, aes(x = mass, y = gape_width)) + geom_point()
summary(lm(gape_width ~ mass, data = trait_database))
Call:
lm(formula = gape_width ~ mass, data = trait_database)
Residuals:
Min 1Q Median 3Q Max
-5.1630 -0.8190 -0.2109 0.6962 4.9974
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.5774864 0.0979691 36.52 <0.0000000000000002 ***
mass 0.0040627 0.0002789 14.57 <0.0000000000000002 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.197 on 302 degrees of freedom
Multiple R-squared: 0.4127, Adjusted R-squared: 0.4107
F-statistic: 212.2 on 1 and 302 DF, p-value: < 0.00000000000000022
ggplot(trait_database, aes(x = mass, y = handwing_index)) + geom_point()
summary(lm(handwing_index ~ mass, data = trait_database))
Call:
lm(formula = handwing_index ~ mass, data = trait_database)
Residuals:
Min 1Q Median 3Q Max
-15.8365 -3.6549 -0.1984 4.0155 17.4322
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 31.583521 0.465849 67.798 <0.0000000000000002 ***
mass -0.001694 0.001326 -1.277 0.202
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 5.693 on 302 degrees of freedom
Multiple R-squared: 0.005373, Adjusted R-squared: 0.00208
F-statistic: 1.631 on 1 and 302 DF, p-value: 0.2025